package logic

import (
	"context"
	"month2/B/rpc_B/user"

	"month2/B/api_B/internal/svc"
	"month2/B/api_B/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateUserStatusLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdateUserStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserStatusLogic {
	return &UpdateUserStatusLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateUserStatusLogic) UpdateUserStatus(req *types.UpdateUserStatusRequest) (resp *types.Response, err error) {
	status, err := l.svcCtx.BRpc.UpdateUserStatus(l.ctx, &user.UpdateUserStatusRequest{
		UserId: int64(req.UserId),
		Status: int64(req.Status),
	})
	if err != nil {
		return &types.Response{
			Msg:  "用户状态修改失败",
			Data: nil,
			Code: 500,
		}, nil
	}
	return &types.Response{
		Msg:  "用户状态修改成功",
		Data: status,
		Code: 200,
	}, nil
}
